log using C:\docs\bfs\_restatrev\logs\tables1&2-sum.log, replace

#delimit ;
set more off;

***** table 1, col 1 - descriptive stats for full w1-w2 sample;
**************************************************************;
use C:\DATA\BF\w1w2all.dta, clear;

*w2 sex indicators;
gen touch = inlist(sex,1,2);
gen hadsex = sex==2;

foreach var in sex age male black orace gpa pdevo risk future time 
	hhsmoke twoparhh pchurch nonech nopch parhs parcoll nopeduc
	w1sex1_ w1sex2_ w1smoketry w1smokereg w1pottry w1potreg 
	w1alctry w1alcreg w1skipany w1skipreg { ;
drop if `var'==.;
};


tabstat touch hadsex age male black orace gpa pdevo risk future time 
	hhsmoke twoparhh pchurch nonech nopch parhs parcoll nopeduc
	w1sex1_ w1sex2_ w1smoketry w1smokereg w1pottry w1potreg 
	w1alctry w1alcreg w1skipany w1skipreg 
	, stat(mean n) f(%6.3f) col(stat);

tabstat pchurch nonech if nopch==0, stat(mean n) f(%6.2f) col(stat);
tabstat parhs parcoll if nopeduc==0, stat(mean n) f(%6.2f) col(stat);

*******************************************************************************;
***** table 1, col 2 - descriptive stats for all w1-w2 friend pairs;
***** table 2, cols 1&2 - correlation in covariates for all w1-w2 friend pairs;
*******************************************************************************;
#delimit ;
use BF\friends.dta, clear;
*******sample and dependent var definition;*******choose sample and delete obs with missing dep var;drop if sex1==.;drop if sex2==.;
*parent educ;replace parcoll1=0 if nopeduc1==1;
replace parcoll2=0 if nopeduc2==1;

*w1 sex indicators;gen w1sex1_1 = inlist(w1sex1,1,2);
gen w1sex1_2 = inlist(w1sex2,1,2);
gen w1sex2_1 = w1sex1==2;
gen w1sex2_2 = w1sex2==2;

*w2 sex indicators;gen sex1_1 = inlist(sex1,1,2);
gen sex1_2 = inlist(sex2,1,2);
gen sex2_1 = sex1==2;
gen sex2_2 = sex2==2;

*w1 behaviors-check;
tab w1smoketry1 w1smokereg1, mis;
tab w1smoketry2 w1smokereg2, mis;
tab w1pottry1 w1potreg1, mis;
tab w1pottry2 w1potreg2, mis;
tab w1skipany1 w1skipreg1, mis;
tab w1skipany2 w1skipreg2, mis;
tab w1sex1_1 w1sex2_1, mis;
tab w1sex1_2 w1sex2_2, mis;

***drop missing covariates;drop if nogpa1==1;drop if nogpa2==1;drop if age1==.;drop if age2==.;drop if gpa1==.;drop if gpa2==.;drop if risk1==.;drop if risk2==.;drop if time1==.;drop if time2==.;drop if future1==.;drop if future2==.;drop if twoparhh1==.;drop if twoparhh2==.;drop if hhsmoke1==.;drop if hhsmoke2==.;drop if pchurch1==.;drop if pchurch2==.;drop if nopch1==.;drop if nopch2==.;drop if pdevo1==.;drop if pdevo2==.;
drop if parhs1==.;
drop if parhs2==.;
drop if parcoll1==.;
drop if parcoll2==.;
drop if nopeduc1==.;
drop if nopeduc2==.;

egen missw1 = rowmiss(w1sex1 w1sex2 w1smoketry1 w1smoketry2 w1smokereg1 w1smokereg2
			w1pottry1 w1pottry2 w1potreg1 w1potreg2 
			w1alctry1 w1alctry2 w1alcreg1 w1alcreg2
			w1skipany1 w1skipany2 w1skipreg1 w1skipreg2);
replace missw1=missw1~=0;
count if missw1==1;
drop if missw1==1;

# delimit ;
*********************** simple correlations in covariates b/w friend pairs;
foreach var in age black gpa pdevo risk future time 
	hhsmoke twoparhh 
	w1sex1_ w1sex2_ w1smoketry w1smokereg w1pottry w1potreg 
	w1alctry w1alcreg w1skipany w1skipreg {;	
	corr(`var'1 `var'2);
	scalar c`var' = r(rho);
};

foreach var in pchurch nonech {;
	corr(`var'1 `var'2) if nopch1==0&nopch2==0;
	scalar c`var' = r(rho);
};
	
foreach var in parhs parcoll {;
	corr(`var'1 `var'2) if nopeduc1==0&nopeduc2==0;
	scalar c`var' = r(rho);
};

# delimit ;
foreach var in age black gpa pdevo risk future time 
	hhsmoke twoparhh pchurch nonech parhs parcoll
	w1sex1_ w1sex2_ w1smoketry w1smokereg w1pottry w1potreg 
	w1skipany w1skipreg w1alctry w1alcreg {	;
	di "`var'             " c`var' ;
};

*********************** partial correlation coefficients, controlling for gender, age & race;
foreach var in age black gpa pdevo risk future time 
	hhsmoke twoparhh w1sex1_ w1sex2_ w1smoketry w1smokereg 
	w1pottry w1potreg w1skipany w1skipreg alctry w1alcreg {;	
	pcorr(`var'1 `var'2 male1 age1 age2 black1 black2 orace1 orace2 ) ;
};

foreach var in pchurch nonech {;
	pcorr(`var'1 `var'2 male1 age1 age2 black1 black2 orace1 orace2) if nopch1==0&nopch2==0;
};
	
foreach var in parhs parcoll {;
	pcorr(`var'1 `var'2 male1 age1 age2 black1 black2 orace1 orace2) if nopeduc1==0&nopeduc2==0;
};


*********************** Descriptive stats;
reshape long sex1_ sex2_ male age black orace gpa pdevo risk future time 
	hhsmoke twoparhh pchurch nonech nopch parhs parcoll nopeduc
	w1sex1_ w1sex2_ w1smoketry w1smokereg w1pottry w1potreg 
	w1alctry w1alcreg w1skipany w1skipreg 
	, i(matchid) ;
tabstat age male black orace gpa pdevo risk future time 
	hhsmoke twoparhh pchurch nonech nopch parhs parcoll nopeduc
	w1sex1_ w1sex2_ w1smoketry w1smokereg w1pottry w1potreg 
	w1alctry w1alcreg w1skipany w1skipreg 
	, stat(mean n) f(%6.2f) col(stat);

tabstat pchurch nonech if nopch==0, stat(mean n) f(%6.2f) col(stat);
tabstat parhs parcoll if nopeduc==0, stat(mean n) f(%6.2f) col(stat);
tabstat sex1_ sex2_ , stat(mean n) f(%6.3f) col(stat);

*********************************************************************************;
***** table 1, col 3 - descriptive stats for sex op estimation sample
***** table 2, cols 3&4 - correlation in covariates for sex op estimation sample
*********************************************************************************;
#delimit ;
use BF\friends.dta, clear;
drop if nosex1smpl!=1;

*******sample and dependent var definition;
*******choose sample and delete obs with missing dep var;
drop if sex1==.;
drop if sex2==.;

*parent educ;
replace parcoll1=0 if nopeduc1==1;
replace parcoll2=0 if nopeduc2==1;

*w1 sex indicators;
gen w1sex1_1 = inlist(w1sex1,1,2);
gen w1sex1_2 = inlist(w1sex2,1,2);
gen w1sex2_1 = w1sex1==2;
gen w1sex2_2 = w1sex2==2;

*w2 sex indicators;
gen sex1_1 = inlist(sex1,1,2);
gen sex1_2 = inlist(sex2,1,2);
gen sex2_1 = sex1==2;
gen sex2_2 = sex2==2;

*w1 behaviors-check;
tab w1smoketry1 w1smokereg1, mis;
tab w1smoketry2 w1smokereg2, mis;
tab w1pottry1 w1potreg1, mis;
tab w1pottry2 w1potreg2, mis;
tab w1skipany1 w1skipreg1, mis;
tab w1skipany2 w1skipreg2, mis;
tab w1sex1_1 w1sex2_1, mis;
tab w1sex1_2 w1sex2_2, mis;

***drop missing covariates;
drop if nogpa1==1;
drop if nogpa2==1;
drop if age1==.;
drop if age2==.;
drop if gpa1==.;
drop if gpa2==.;
drop if risk1==.;
drop if risk2==.;
drop if time1==.;
drop if time2==.;
drop if future1==.;
drop if future2==.;
drop if twoparhh1==.;
drop if twoparhh2==.;
drop if hhsmoke1==.;
drop if hhsmoke2==.;
drop if pchurch1==.;
drop if pchurch2==.;
drop if nopch1==.;
drop if nopch2==.;
drop if pdevo1==.;
drop if pdevo2==.;
drop if parhs1==.;
drop if parhs2==.;
drop if parcoll1==.;
drop if parcoll2==.;
drop if nopeduc1==.;
drop if nopeduc2==.;

egen missw1 = rowmiss(w1sex1 w1sex2 w1smoketry1 w1smoketry2 w1smokereg1 w1smokereg2
			w1pottry1 w1pottry2 w1potreg1 w1potreg2 
			w1alctry1 w1alctry2 w1alcreg1 w1alcreg2
			w1skipany1 w1skipany2 w1skipreg1 w1skipreg2);
replace missw1=missw1~=0;
count if missw1==1;
drop if missw1==1;

# delimit ;
*********************** simple correlations in covariates b/w friend pairs;
foreach var in age black gpa pdevo risk future time 
	hhsmoke twoparhh 
	w1sex1_ w1sex2_ w1smoketry w1smokereg w1pottry w1potreg 
	w1alctry w1alcreg w1skipany w1skipreg {;	
	corr(`var'1 `var'2);
	scalar c`var' = r(rho);
};

foreach var in pchurch nonech {;
	corr(`var'1 `var'2) if nopch1==0&nopch2==0;
	scalar c`var' = r(rho);
};
	
foreach var in parhs parcoll {;
	corr(`var'1 `var'2) if nopeduc1==0&nopeduc2==0;
	scalar c`var' = r(rho);
};

# delimit ;
foreach var in age black gpa pdevo risk future time 
	hhsmoke twoparhh pchurch nonech parhs parcoll
	w1sex1_ w1sex2_ w1smoketry w1smokereg w1pottry w1potreg 
	w1skipany w1skipreg w1alctry w1alcreg {	;
	di "`var'             " c`var' ;
};

*********************** partial correlation coefficients, controlling for gender, age & race;
foreach var in age black gpa pdevo risk future time 
	hhsmoke twoparhh w1sex1_ w1sex2_ w1smoketry w1smokereg 
	w1pottry w1potreg w1skipany w1skipreg alctry w1alcreg {;	
	pcorr(`var'1 `var'2 male1 age1 age2 black1 black2 orace1 orace2 ) ;
};

foreach var in pchurch nonech {;
	pcorr(`var'1 `var'2 male1 age1 age2 black1 black2 orace1 orace2) if nopch1==0&nopch2==0;
};
	
foreach var in parhs parcoll {;
	pcorr(`var'1 `var'2 male1 age1 age2 black1 black2 orace1 orace2) if nopeduc1==0&nopeduc2==0;
};


*********************** Descriptive stats;
reshape long sex1_ sex2_ male age black orace gpa pdevo risk future time 
	hhsmoke twoparhh pchurch nonech nopch parhs parcoll nopeduc
	w1sex1_ w1sex2_ w1smoketry w1smokereg w1pottry w1potreg 
	w1alctry w1alcreg w1skipany w1skipreg 
	, i(matchid) ;
tabstat age male black orace gpa pdevo risk future time 
	hhsmoke twoparhh pchurch nonech nopch parhs parcoll nopeduc
	w1sex1_ w1sex2_ w1smoketry w1smokereg w1pottry w1potreg 
	w1alctry w1alcreg w1skipany w1skipreg 
	, stat(mean n) f(%6.2f) col(stat);

tabstat pchurch nonech if nopch==0, stat(mean n) f(%6.2f) col(stat);
tabstat parhs parcoll if nopeduc==0, stat(mean n) f(%6.2f) col(stat);
tabstat sex1_ sex2_ , stat(mean n) f(%6.3f) col(stat);



log close;

view C:\docs\bfs\_restatrev\logs\tables1&2-sum.log;










